import React from 'react'
import { TouchableOpacity, Text } from 'react-native'
import PropTypes from 'prop-types'

/**
 * 文字点击按钮
 *
 * @export
 * @class TextButton
 * @extends {React.Component}
 */
export default class TextButton extends React.Component {
  static propTypes = {
    text: PropTypes.string.isRequired, // 文字内容
    onPress: PropTypes.func.isRequired, // 点击回调
    activeOpacity: PropTypes.number, // 点击时透明度
    style: PropTypes.object, // 文字的样式
    touchStyle: PropTypes.object // 点击区域的样式
  }

  static defaultProps = {
    activeOpacity: 0.8,
    touchStyle: {
      justifyContent: 'center',
      alignItems: 'center'
    }
  }

  render() {
    return (
      <TouchableOpacity
        style={this.props.touchStyle}
        activeOpacity={this.props.activeOpacity}
        onPress={this.props.onPress}
      >
        <Text style={this.props.style}>{this.props.text}</Text>
      </TouchableOpacity>
    )
  }
}
